Socket
Socket
Sign inDemoInstall

klona

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

klona

A tiny (423B) and fast utility to "deep clone" Objects, Arrays, Dates, RegExps, and more!


Version published
Weekly downloads
11M
decreased by-1.69%
Maintainers
1
Weekly downloads
 
Created

What is klona?

The klona npm package is a JavaScript utility for deep cloning objects. It allows developers to create a deep copy of an object, ensuring that changes to the new object do not affect the original object. This is particularly useful when working with complex data structures or when you need to ensure data immutability.

What are klona's main functionalities?

Deep cloning of objects

This feature allows you to create a deep clone of an object, which means that nested objects are also cloned, and changes to the cloned object do not affect the original object.

{"const klona = require('klona');\nconst original = { a: 1, b: { c: 2 } };\nconst copy = klona(original);\ncopy.b.c = 3;\nconsole.log(original.b.c); // 2\nconsole.log(copy.b.c); // 3"}

Deep cloning of arrays

Similar to object cloning, klona can also deep clone arrays, including nested arrays, ensuring that modifications to the cloned array do not affect the original array.

{"const klona = require('klona');\nconst original = [1, [2, 3], [4, 5]];\nconst copy = klona(original);\ncopy[1][0] = 'changed';\nconsole.log(original[1][0]); // 2\nconsole.log(copy[1][0]); // 'changed'"}

Cloning class instances

klona is capable of cloning instances of classes, allowing you to duplicate an instance and modify the copy without affecting the original instance.

{"const klona = require('klona');\nclass Example {\n  constructor(value) {\n    this.value = value;\n  }\n}\nconst original = new Example(1);\nconst copy = klona(original);\ncopy.value = 2;\nconsole.log(original.value); // 1\nconsole.log(copy.value); // 2"}

Other packages similar to klona

Keywords

FAQs

Package last updated on 04 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc